<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加账户</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
     <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/js/laypage/skin/laypage.css" media="all">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <script type="text/javascript" src="/lib/layui/layui.js"></script>
    <script src="/Vue/vue.min.js"></script>
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/laypage/laypage.js" charset="utf-8"></script>
    <script src="/js/layer/layer.js" charset="utf-8"></script>
</head>
<body>
<div class="container" id="app">
    <form id="addAccountForm" class="layui-form" action="">
        <br/>
        <div >
            <label for="zhanghu">账户名称：</label>
            <input type="text"  id="zhanghu" name="zhanghu" placeholder="输入账户名称">
        </div>
        <div class="form-group">
            <label for="sabank">开户银行：</label>
            <input type="text" class="form-control" id="sabank" name="sabank" placeholder="开户银行">
        </div>
        <div class="form-group">
        <label for="sabanknumber">银行账号：</label>
        <input type="text" class="form-control" id="sabanknumber" name="sabanknumber" placeholder="银行账号18-21位"><span id="spannumber"></span>
    </div>
        <div class="form-group">
            <label for="beginbalance">期初余额：</label>
            <input type="text" class="form-control" id="beginbalance" name="beginbalance" placeholder="期初余额"><span id="spanbeginbalance" ></span>
        </div>
        <div class="form-group">
            <label for="zhangbalance">账户余额：</label>
            <input type="text" class="form-control" id="zhangbalance" name="zhangbalance" placeholder="账户余额"><span id="spanzhangbalance"></span>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="checkbox" id="sysData" value="1" name="sysData" lay-skin="switch" lay-filter="switchTest" lay-text="正常|禁用" checked="">
            </div>
        </div>
        <div class="form-group">
            <label for="remark">备注：</label>
            <textarea class="form-control" id="remark" name="remark" ></textarea>
        </div>
        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">提交</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
<script>
    var addAccount=function () {
        $.ajax({
            type:'get',
            dataType:'json',
            url:"/basicdata/settlement-account/insertaccount",
            data:{
                zhanghu:$("#zhanghu").val(),
                sabank:$("#sabank").val(),
                sabanknumber:$("#sabanknumber").val(),
                beginbalance:$("#beginbalance").val(),
                zhangbalance:$("#zhangbalance").val(),
                zhangstate:$("input:checkbox[name='sysData']:checked").val()==1 ? '正常':'禁用',
            },
            success:function () {
                $("#cancelBtn").click();
            }
        });
    }
    $("#saveBtn").click(function () {
        addAccount();
    });
    $("#cancelBtn").click(function () {
        var index=parent.layer.getFrameIndex(window.name);
        parent.getAccountPageList();
        parent.layer.close(index);
    });
    //验证银行账号
    var chechnumber=false;
    $(function () {
        $("#sabanknumber").on("blur", function () {
            var sabanknumber = $("#sabanknumber").val();
            var reg = /[0-9]{18,21}/;
            var b = reg.test(sabanknumber);
            if (b) {
                $.ajax({
                    type:"post",
                    url: "/basicdata/settlement-account/checkaccount",
                    data: {
                        "sabanknumber": sabanknumber
                    },
                    success: function (result, state, xhr) {
                        if (result == "success") {
                            $("#spannumber").html("<strong style='color: #1e97f7'>银行账号已存在</strong>");
                            chechnumber = true;
                        } else {
                            $("#spannumber").html("<strong style='color: #1e97f7'>正确</strong>")
                        }
                    },
                    dataType: "text"
                })
            } else {
                $("#spannumber").html("<strong style='color: red'>此银行账号错误</strong>")
            }
        });
    });
    //验证期初余额
    var beg=false;
    $("#beginbalance").on("blur",function () {
        var beginbalance=$("#beginbalance").val();
        var reg=/[0-9]/;
        var b=reg.test(beginbalance);
        if(b){
            $("#spanbeginbalance").html("<strong style='color: #1e97f7'>输入正确</strong>")
            beg=true;
        }else{
            $("#spanbeginbalance").html("<strong style='color: red'>格式错误</strong>")
        }
    });
    //验证账户余额
    var zhang=false;
    $("#zhangbalance").on("blur",function () {
        var zhangbalance=$("#zhangbalance").val();
        var reg=/[0-9]/;
        var b=reg.test(zhangbalance);
        if(b){
            $("#spanzhangbalance").html("<strong style='color: #1e97f7'>输入正确</strong>")
            zhang=true;
        }else{
            $("#spanzhangbalance").html("<strong  style='color: red'>格式错误</strong>")
        }
    });
    layui.use(['form','jquery'],function () {
        var $ = layui.jquery;
        var form = layui.form;
        form.render();
            })
</script>
</body>
</html>